/************************************************************************************************
 * test examples of 100 interesting program in C
 * test 009.c
 * yanghui triangle
 ***********************************************************************************************/

#include <stdio.h>

/*
 * original solution in book assume that most number width to be 6
 * assume that most number width is 3(3+1blank=4), we can print this more beautiful
 * BTW, this solution use recursive, non-recursive way will be much more faster
 */

int c(int x, int y);

int main()
{
	int i = 0, j = 0, n;
	printf("N(<=13)=");
	scanf("%d", &n);
	for (i = 0;  i < n; i++)
	{
		for (j = 1; j < n-i; j++) printf("  ");
		for (j = 1; j < i+2; j++) printf("%4d", c(i, j));
		printf("\n");
	}
}

int c(int x, int y)
{
	int z = 0;
	if (y == 1 || (y == x+1)) return(1);
	z = c(x-1, y-1) + c(x-1, y);
	return(z);
}

